package com.woniu.sharepark.leasesystem.lessor.controller;

import com.woniu.sharepark.common.JsonResult;
import com.woniu.sharepark.leasesystem.lessor.dto.CarParkDTO;
import com.woniu.sharepark.leasesystem.lessor.pojo.CarPark;
import com.woniu.sharepark.leasesystem.lessor.service.CarParkService;
import com.woniu.sharepark.propertysystem.dto.CommunityDTO;
import com.woniu.sharepark.propertysystem.pojo.Community;
import com.woniu.sharepark.propertysystem.service.CommunityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;

/**
 * @ClassName: LessorController
 * @Description: 此为出租人Controller
 * @Author: Zongjie.Li
 * @Date: 2019/6/4
 * @Version: 1.0
 **/
@Controller
@RequestMapping("/lessor")
public class LessorController {

    @Autowired
    private CommunityService communityServiceImpl;

    @Autowired
    private CarParkService carParkServiceImpl;

    @ResponseBody
    @RequestMapping("/search")
    public List<Community> searchCommunity(CommunityDTO communityDTO) {
        return communityServiceImpl.searchCommunity(communityDTO);
    }

    @ResponseBody
    @RequestMapping("/addcarpark")
    public JsonResult addCarPark(CarParkDTO carParkDTO){
        return carParkServiceImpl.addCarPark(carParkDTO);
    }

    @ResponseBody
    @RequestMapping("/usefulcarpark")
    public JsonResult searchCarPark(){
        return carParkServiceImpl.findUsefulCarPark();
    }

    @ResponseBody
    @RequestMapping("/findCarParkById")
    public JsonResult findCarParkById(Integer id) {
         JsonResult jsonResult = carParkServiceImpl.findCarParkById(id);
        System.out.println(jsonResult.getResult());
        return jsonResult;
    }

    @RequestMapping("/findParkByComId")
    @ResponseBody
    public List<CarPark> findParkByComId(CarPark carPark){
        List<CarPark> result = carParkServiceImpl.findCarParkSelective(carPark);
        return result;
    }


    @ResponseBody
    @RequestMapping("/mycarpark")
    public JsonResult myCarPark(){
        return carParkServiceImpl.findMyCarPark();
    }

    @ResponseBody
    @RequestMapping("/income")
    public JsonResult getIncomeYesterday(){
        return carParkServiceImpl.getIncomeYesterday();
    }

    @ResponseBody
    @RequestMapping("/upcarpark")
    public JsonResult upCarPark(CarPark carPark){
        return carParkServiceImpl.upCarPark(carPark);
    }
    @ResponseBody
    @RequestMapping("/downcarpark")
    public JsonResult downCarPark(CarPark carPark){
        return carParkServiceImpl.downCarPark(carPark);
    }
}
